package com.duan.service;

import com.duan.mapper.MemberMapper;
import com.duan.mapper.SettingMapper;
import com.duan.pojo.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberService {
    private final MemberMapper memberMapper;

    private final SettingMapper settingMapper;

    @Autowired
    public MemberService(MemberMapper memberMapper, SettingMapper settingMapper){
        this.memberMapper = memberMapper;
        this.settingMapper = settingMapper;
    }

    /****
     * 获取此次抽奖的所有参加成员信息
     * @param settingId 此次抽奖设置的id
     * @return 参与此次抽奖的所有成员
     */
    public List<Member> queryBySettingId(Integer settingId){
        return memberMapper.selectMembersBySettingId(settingId);
    }


    /***
     * 增加
     * @param member 用户（仅有姓名、工号属性）
     * @param userId 用户Id
     * @return 变动行数
     */
    public int add(Member member, Integer userId){
        //1、先获取settingId
        Integer settingId = settingMapper.queryIdByUserId(userId);
        //2、将settingId设置到member中
        member.setSettingId(settingId);
        //3、将member对象插入
        return memberMapper.insertSelective(member);
    }

    //修改
    public int update(Member member){
        return memberMapper.updateByPrimaryKeySelective(member);
    }

    //删除
    public int delete(Integer memberId){
        return memberMapper.deleteByPrimaryKey(memberId);
    }

}
